package org.samith.dao;

import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import javax.persistence.Query;

import org.samith.entity.AdminUser;

@Stateless
public class AdminUserDaoImpl extends BaseDaoImpl<AdminUser> implements AdminUserDao{
	@Override
	public Class<AdminUser> getType() {
		return AdminUser.class;
	}
	
	public AdminUser findByUserName(String username){
		Query query = em.createQuery("SELECT a FROM AdminUser a WHERE a.userName = :u ");
		query.setParameter("u", username);
		AdminUser admin;
		try{
			admin = (AdminUser) query.getSingleResult();
		}catch(NoResultException ex){
			System.out.println("========== No admin user found ================");
			return null;
		}
		return admin;
	}
}
